package cn.dgiot.fd.service.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.dgiot.fd.dao.IPLCWarnFlowDAO;
import cn.dgiot.fd.model.DeviceStateModel;
import cn.dgiot.fd.model.PLCWarnFlowModel;
import cn.dgiot.fd.service.IDeviceStateService;
import cn.dgiot.fd.service.IPLCWarnFlowService;

/**
 * [下位机告警流水]
 * @author
 *
 */
@Service
public class PLCWarnFlowServiceImpl implements IPLCWarnFlowService{
 
	@Autowired
	private IPLCWarnFlowDAO plcWarnFlowDAO;

	@Autowired
	private IDeviceStateService deviceStateService;
	
	@Override
	public void insertPLCWarn(PLCWarnFlowModel plcWarnFlowModel) {
		List<PLCWarnFlowModel> plcWarnModelList = new ArrayList<PLCWarnFlowModel>();
		String deviceName = plcWarnFlowModel.getDeviceName();
		DeviceStateModel deviceStateModel = new DeviceStateModel();
    	deviceStateModel.setDeviceName(deviceName);
    	deviceStateModel.setProductKey(plcWarnFlowModel.getProductKey());
    	DeviceStateModel deviceStateModelResult = deviceStateService.getDeviceState(deviceStateModel);
		PLCWarnFlowModel param = new PLCWarnFlowModel();
		param.setIotId(deviceStateModelResult.getIotId());
		param.setDeviceName(deviceName);
		param.setProductKey(plcWarnFlowModel.getProductKey());
		param.setWtype(plcWarnFlowModel.getWtype());
		param.setVal(plcWarnFlowModel.getVal());
		param.setStatus(plcWarnFlowModel.getStatus());
		param.setCreateTime(plcWarnFlowModel.getCreateTime());
		param.setId(UUID.randomUUID().toString().replace("-", ""));
		param.setRequestId(plcWarnFlowModel.getRequestId());
		param.setDpno(plcWarnFlowModel.getDpno());
		plcWarnModelList.add(param);
		plcWarnFlowDAO.insertPLCWarn(plcWarnModelList);
	}

	@Override
	public void updatePLCWarnStatus(PLCWarnFlowModel plcWarnFlowModel) {
		// TODO Auto-generated method stub
		plcWarnFlowDAO.updatePLCWarnStatus(plcWarnFlowModel);
	}

}
